<template>
  <div>
    <operation-title
      title="商品组"
      :icon="TitleIcon"
    />
    <div class="divider" />
    <div class="func">
      <p class="attr">
        样式
      </p>
      <ul class="common-ul">
        <li
          :class="config.pageConfig.style == '1' ? 'active' : ''"
          @click="config.pageConfig.style = '1'"
        >
          默认
        </li>
        <li
          :class="config.pageConfig.style == '2' ? 'active' : ''"
          @click="config.pageConfig.style = '2'"
        >
          投影
        </li>
        <li
          :class="config.pageConfig.style == '3' ? 'active' : ''"
          @click="config.pageConfig.style = '3'"
        >
          描边
        </li>
      </ul>
      <div
        v-if="config.pageConfig.style == '3'"
        class="adjust-item"
      >
        <el-color-picker v-model="config.pageConfig.borderColor" />
        <span>{{ config.pageConfig.borderColor }}</span>
      </div>
      <div
        v-if="config.pageConfig.style == '3'"
        class="adjust-item"
      >
        <el-slider
          v-model="config.pageConfig.borderWidth"
          :min="0"
          :max="5"
          show-input
          size="small"
        />
        px
      </div>
    </div>
    <div class="divider" />
    <div class="func">
      <p class="attr">
        选择风格
      </p>
      <ul class="common-ul">
        <li
          :class="config.pageConfig.custom == '1' ? 'active' : ''"
          @click="changeCustom('1')"
        >
          <img
            src="../../../../../../assets/app/other/goods/goods-one.png"
            alt=""
          >
        </li>
        <li
          :class="config.pageConfig.custom == '2' ? 'active' : ''"
          @click="changeCustom('2')"
        >
          <img
            src="../../../../../../assets/app/other/goods/goods-two.png"
            alt=""
          >
        </li>
        <li
          :class="config.pageConfig.custom == '3' ? 'active' : ''"
          @click="changeCustom('3')"
        >
          <img
            src="../../../../../../assets/app/other/goods/goods-three.png"
            alt=""
          >
        </li>
        <li
          :class="config.pageConfig.custom == '7' ? 'active' : ''"
          @click="changeCustom('7')"
        >
          <img
            src="../../../../../../assets/app/other/goods/goods-seven.png"
            alt=""
          >
        </li>
      </ul>
    </div>
    <div class="divider" />
    <select-goods-setting
      v-model:page-config="pageConfig"
      :disable-types="['all']"
    />
    <div class="divider" />
    <div class="func">
      <p class="attr">
        颜色设置
      </p>
      <div class="adjust-item">
        <span>底部背景</span>
        <el-color-picker v-model="config.pageConfig.color" />
        <span>{{ config.pageConfig.color }}</span>
      </div>
      <div class="adjust-item">
        <span>商品背景</span>
        <el-color-picker v-model="config.pageConfig.goodsColor" />
        <span>{{ config.pageConfig.goodsColor }}</span>
      </div>
    </div>

    <div class="divider" />

    <!--    显示内容-->
    <goods-content-setting v-model:page-config="config.pageConfig" />

    <div class="divider" />

    <!--    内容对齐-->
    <content-alignment
      v-if="config.pageConfig.custom === '7'"
      v-model:page-config="config.pageConfig"
    />

    <div class="divider" />

    <!--    购买按钮-->
    <purchase-button-setting
      v-if="config.pageConfig.custom == '1' ||
        config.pageConfig.custom == '2' ||
        config.pageConfig.custom == '3'
      "
      v-model:page-config="config.pageConfig"
    />

    <div class="divider" />
    <div class="func">
      <p class="attr">
        角标设置
      </p>
      <ul class="common-ul">
        <li
          :class="config.pageConfig.dotSetting == '1' ? 'active' : ''"
          @click="config.pageConfig.dotSetting = '1'"
        >
          不显示
        </li>
        <li
          :class="config.pageConfig.dotSetting == '2' ? 'active' : ''"
          @click="config.pageConfig.dotSetting = '2'"
        >
          系统图标
        </li>
        <li
          :class="config.pageConfig.dotSetting == '3' ? 'active' : ''"
          @click="config.pageConfig.dotSetting = '3'"
        >
          自定义
        </li>
      </ul>
      <div v-if="config.pageConfig.dotSetting == '2'">
        <div class="adjust-item">
          <span>样式</span>
          <ul class="common-ul">
            <li
              :class="config.pageConfig.dotStyle == '1' ? 'active' : ''"
              @click="config.pageConfig.dotStyle = '1'"
            >
              <img
                src="../../../../../../assets/app/other/goods/hot.png"
                alt=""
              >
            </li>
            <li
              :class="config.pageConfig.dotStyle == '2' ? 'active' : ''"
              @click="config.pageConfig.dotStyle = '2'"
            >
              <img
                src="../../../../../../assets/app/other/goods/hot-2.png"
                alt=""
              >
            </li>
            <li
              :class="config.pageConfig.dotStyle == '3' ? 'active' : ''"
              @click="config.pageConfig.dotStyle = '3'"
            >
              <img
                src="../../../../../../assets/app/other/goods/hot-3.png"
                alt=""
              >
            </li>
          </ul>
        </div>
        <div class="adjust-item">
          <span>文字</span>
          <el-input
            v-model.trim="config.pageConfig.dotName"
            class="input-content"
            size="small"
            type="text"
            maxlength="2"
            :show-word-limit="true"
          />
        </div>
      </div>
      <div v-if="config.pageConfig.dotSetting == '3'">
        <h4>建议图片宽高76px*76px</h4>
        <div class="img-placeholder">
          <div
            v-if="config.pageConfig.dotUrl"
            class="upload-img"
          >
            <el-image
              style="width: 100%; height: 100%"
              :src="config.pageConfig.dotUrl"
              fit="contain"
            />
            <div class="upload-img_cover">
              <Upload
                :model-value="dotfileList"
                file-path="actapp/"
                :limit="999"
                :show-file-list="false"
                @success="success"
              >
                <el-button size="small">
                  替换
                </el-button>
              </Upload>
            </div>
          </div>
          <Upload
            v-else
            v-model="config.pageConfig.dotUrl"
            file-path="actapp/"
            list-type="picture-card"
          >
            <el-icon>
              <Plus />
            </el-icon>
          </Upload>
        </div>
      </div>
    </div>
    <div class="divider" />
    <div class="func">
      <p class="attr">
        边距
      </p>
      <div class="adjust-item">
        <span>商品间距</span>
        <el-slider
          v-model="config.pageConfig.distance"
          :min="0"
          :max="20"
          show-input
          size="small"
        />
        px
      </div>
      <div class="adjust-item">
        <span>上边距</span>
        <el-slider
          v-model="config.pageConfig.marginTop"
          :min="0"
          :max="50"
          show-input
          size="small"
        />
        px
      </div>
      <div class="adjust-item">
        <span>下边距</span>
        <el-slider
          v-model="config.pageConfig.marginBottom"
          :min="0"
          :max="50"
          show-input
          size="small"
        />
        px
      </div>
      <div class="adjust-item">
        <span>左右边距</span>
        <el-slider
          v-model="config.pageConfig.margin"
          :min="0"
          :max="20"
          show-input
          size="small"
        />
        px
      </div>
    </div>
    <div class="divider" />
    <div class="func">
      <p class="attr">
        圆角设置
      </p>
      <div class="adjust-item">
        <span>上圆角</span>
        <el-slider
          v-model="config.pageConfig.radiusTop"
          :min="0"
          :max="20"
          show-input
          size="small"
        />
        px
      </div>
      <div class="adjust-item">
        <span>下圆角</span>
        <el-slider
          v-model="config.pageConfig.radiusBottom"
          :min="0"
          :max="20"
          show-input
          size="small"
        />
        px
      </div>
    </div>
    <div class="divider" />
  </div>
</template>

<script lang="ts">
export default {
  name: "GoodsGroupOperation",
};
</script>
<script lang="ts" setup>
import { onMounted, Ref } from "vue";
import {
  IPurchaseButtonPageConfig,
  purchaseButtonPageConfig
} from "@/views/activity/actApp/components/default/operationComponents/purchaseButtonSetting";
import PurchaseButtonSetting
  from "@/views/activity/actApp/components/default/operationComponents/purchaseButtonSetting/PurchaseButtonSetting.vue";
import SelectGoodsSetting
  from "@/views/activity/actApp/components/default/operationComponents/selectGoodsSetting/SelectGoodsSetting.vue";
import {
  ISelectGoodsSettingPageConfig,
  selectGoodsSettingPageConfig
} from "@/views/activity/actApp/components/default/operationComponents/selectGoodsSetting";
import GoodsContentSetting
  from "@/views/activity/actApp/components/default/operationComponents/goodsContentSetting/GoodsContentSetting.vue";
import {
  goodsContentSettingPageConfig,
  IGoodsContentSettingPageConfig
} from "@/views/activity/actApp/components/default/operationComponents/goodsContentSetting";
import ContentAlignment
  from "@/views/activity/actApp/components/default/operationComponents/contentAlignment/ContentAlignment.vue";
import {
  contentAlignmentPageConfig,
  IContentAlignmentPageConfig
} from "@/views/activity/actApp/components/default/operationComponents/contentAlignment";
import TitleIcon from "@/assets/app/icon/goods.png";
import OperationTitle
  from "@/views/activity/actApp/components/default/operationComponents/operationTitle/OperationTitle.vue";


interface IPageConfig extends
  IPurchaseButtonPageConfig,
  ISelectGoodsSettingPageConfig,
  IGoodsContentSettingPageConfig,
  IContentAlignmentPageConfig {
  custom: string;
  style: string;
  color: string;
  goodsColor: string;
  borderWidth: number;
  borderColor: string;
  dotSetting: string;
  dotStyle: string;
  dotName: string;
  dotUrl: string;
  distance: number;
  marginTop: number;
  marginBottom: number;
  marginImg: number;
  margin: number;
  radiusTop: number;
  radiusBottom: number;
}

const config = withDefaults(defineProps<{
  pageConfig: IPageConfig,
}>(), {
  pageConfig: () => ({
    custom: "1",
    style: "1",
    color: "transparent",
    goodsColor: "#ffffff",
    borderWidth: 1,
    borderColor: "#ededed",
    dotSetting: "1",
    dotStyle: "1",
    dotName: "",
    dotUrl: "",
    distance: 10,
    marginTop: 10,
    marginBottom: 10,
    marginImg: 10,
    margin: 10,
    radiusTop: 4,
    radiusBottom: 4,
    chooseClassify: false,
    classifyId: '',
    ...selectGoodsSettingPageConfig, // 选择商品
    ...purchaseButtonPageConfig, // 购买按钮
    ...goodsContentSettingPageConfig, // 显示内容
    ...contentAlignmentPageConfig, // 内容对齐
  }),
});
const emits = defineEmits<{ (e: "changeStyle", configStyle: Object): void }>();

const changeCustom = (custom: string) => {
  config.pageConfig.custom = custom;

  if (custom !== '7') {
    config.pageConfig.contentAlignment = "left";
  }
}

const dotfileList: Ref<string[]> = ref([]);

const success = (value: any) => {
  config.pageConfig.dotUrl = value.url;
};

watch(config, (val) => {
  emits("changeStyle", config.pageConfig);
}, {
  deep: true
});

onMounted(() => {
  // config.pageConfig.imgList.mallId = store.state.pointsMall.mallConfig.id;
  // getGoodsList();
  // getGoodsCateList();
})
</script>

<style lang="scss" scoped>
@use "@/views/activity/actApp/components/default/styles/operation";

.icon-wrapper {
  background: #fd463e;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  padding: 3px;

  .iconfont {
    font-size: 16px;
    line-height: 16px;
    color: #fff !important;
    margin-right: unset !important;
  }
}

.purchase-button__solid {
  padding: 3px;
  background: #fd463e;
  color: #fff;
  border-radius: 4px;
  font-size: 14px;
  line-height: 14px;
}

.purchase-button__empty {
  padding: 3px;
  background: #fff;
  color: #fd463e;
  border-radius: 4px;
  font-size: 14px;
  line-height: 14px;
  border: solid 1px #fd463e;
}
</style>
